package com.ptszyxx.popose.module.main.trip.adapter;

import android.content.Context;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder;
import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ptszyxx.popose.common.utils.YVipUtil;
import com.ptszyxx.popose.databinding.ItemTripBinding;
import com.ptszyxx.popose.module.main.trip.vm.TripVM;
import com.ysg.http.data.entity.trip.TripEntity;
import com.ysg.utils.YImageUtil;
import com.ysg.utils.YStringUtil;
import com.ysg.utils.YUserUtil;

import java.lang.ref.WeakReference;

public class TripAdapter extends BaseQuickAdapter<TripEntity, BaseDataBindingHolder<ItemTripBinding>> {
    private TripVM viewModel;
    private Presenter presenter = new Presenter();
    public TripAdapter(TripVM viewModel) {
        super(R.layout.item_trip);
        this.viewModel = viewModel;
    }

    @Override
    protected void convert(BaseDataBindingHolder<ItemTripBinding> holder, TripEntity item) {
        ItemTripBinding binding = holder.getDataBinding();
        if (binding != null) {
            binding.setEntity(item);
            binding.setViewModel(viewModel);
            binding.setPresenter(presenter);
            binding.executePendingBindings();

            String url = item.getUserImg();
            try {
                if (YStringUtil.isNotEmpty(item.getMedia())){
                    url = item.getMedia().split(",")[0];
                }
            }catch (Exception e){}

            //模糊的
            if (YVipUtil.isVip(getContext(), false)){
                binding.tvNick.setText(item.getUserName());
                YImageUtil.show(binding.ivAvatar, item.getUserImg());
                YImageUtil.show(binding.ivIcon, url);
            }else{
                binding.tvNick.setText("******");
                YImageUtil.showBlur(binding.ivAvatar, item.getUserImg());
                YImageUtil.showBlur(binding.ivIcon, url);
            }

        }
    }

    public static class Presenter{
        public void onItemClick(TripVM viewModel, TripEntity entity){
            viewModel.jumpTripDetail(entity);
        }
    }





}
